

package com.hazelcast.partition.strategy;

import com.hazelcast.internal.serialization.SerializableByConvention;
import com.hazelcast.partition.PartitionAware;
import com.hazelcast.partition.PartitioningStrategy;

/**
 * A {@link PartitioningStrategy} that checks if the key implements {@link PartitionAware}.
 * If so, the {@link PartitionAware#getPartitionKey()} is called. Otherwise null is returned.
 */
@SerializableByConvention
public class DefaultPartitioningStrategy implements PartitioningStrategy {

    @Override
    public Object getPartitionKey(Object key) {
        if (key instanceof PartitionAware aware) {
            return aware.getPartitionKey();
        }
        return null;
    }
}
